x) Fix EOL on file
This commit is contained in:
parent
0bd6b086f6
commit
dcd15a2663
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -19,6 +19,7 @@
|
||||
# Source code
|
||||
# Source code
|
||||
# Source code
|
||||
*.cs text eol=lf
|
||||
*.rs text
|
||||
*.bash text eol=lf
|
||||
*.bat text eol=crlf
|
||||
|
||||
@ -29,26 +29,25 @@ namespace lib
|
||||
public readonly bool writeOutTemplateFiles = true;
|
||||
}
|
||||
|
||||
public interface ConfigBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Config
|
||||
public class Config : ConfigBase
|
||||
{
|
||||
/*
|
||||
static public Config Load( string filename )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
static ConfigCfg s_cfg = new ConfigCfg();
|
||||
//private int _test = 0;
|
||||
|
||||
private static ConfigCfg s_cfg = new();
|
||||
|
||||
static public void startup( string filename )
|
||||
{
|
||||
res.Mgr.register<Config>( load );
|
||||
res.Mgr.register( load );
|
||||
res.Mgr.registerSub( typeof( Config ) );
|
||||
|
||||
s_cfg = Config.load<ConfigCfg>( filename );
|
||||
s_cfg = load<ConfigCfg>( filename );
|
||||
|
||||
}
|
||||
|
||||
@ -141,11 +140,11 @@ namespace lib
|
||||
|
||||
var dirName = Path.GetDirectoryName( templateFile );
|
||||
|
||||
lib.Util.checkAndAddDirectory( dirName );
|
||||
Util.checkAndAddDirectory( dirName );
|
||||
|
||||
log.info( $"Writing out template config of type {t?.Name} in {templateFile}" );
|
||||
|
||||
Config.save( cfg, templateFile );
|
||||
save( cfg, templateFile );
|
||||
}
|
||||
|
||||
return cfg;
|
||||
@ -153,14 +152,14 @@ namespace lib
|
||||
|
||||
static public void save( Config cfg )
|
||||
{
|
||||
Config.save( cfg, cfg.m_filename );
|
||||
save( cfg, cfg._filename );
|
||||
}
|
||||
|
||||
static public void save( Config cfg, String filename )
|
||||
{
|
||||
FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
|
||||
FileStream fs = new( filename, FileMode.Create, FileAccess.Write );
|
||||
|
||||
XmlFormatter2 formatter = new XmlFormatter2();
|
||||
XmlFormatter2 formatter = new();
|
||||
|
||||
formatter.Serialize( fs, cfg );
|
||||
|
||||
@ -168,7 +167,7 @@ namespace lib
|
||||
}
|
||||
#endregion
|
||||
|
||||
private string m_filename = "{unknown}";
|
||||
private string _filename = "{unknown}";
|
||||
|
||||
public Config()
|
||||
{
|
||||
@ -176,12 +175,12 @@ namespace lib
|
||||
|
||||
public Config( string filename )
|
||||
{
|
||||
m_filename = filename;
|
||||
_filename = filename;
|
||||
}
|
||||
|
||||
public String Filename { get { return m_filename; } }
|
||||
public String Filename { get { return _filename; } }
|
||||
|
||||
protected void SetFilename( String filename ) { m_filename = filename; }
|
||||
protected void SetFilename( String filename ) { _filename = filename; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,8 +10,6 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using static System.Net.WebRequestMethods;
|
||||
using System.Linq;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
@ -70,22 +68,22 @@ namespace lib
|
||||
{
|
||||
}
|
||||
|
||||
public class ChildAttributes : Attribute
|
||||
public class ChildAttribute : Attribute
|
||||
{
|
||||
public string[] Values { get; private set; }
|
||||
|
||||
public ChildAttributes( params string[] values )
|
||||
public ChildAttribute( params string[] values )
|
||||
{
|
||||
this.Values = values;
|
||||
}
|
||||
}
|
||||
|
||||
public class ChildFieldsAttribute : ChildAttributes
|
||||
public class ChildFieldsAttribute : ChildAttribute
|
||||
{
|
||||
public ChildFieldsAttribute( params string[] values ) : base( values ) { }
|
||||
}
|
||||
|
||||
public class ChildPropsAttribute : ChildAttributes
|
||||
public class ChildPropsAttribute : ChildAttribute
|
||||
{
|
||||
public ChildPropsAttribute( params string[] values ) : base( values ) { }
|
||||
}
|
||||
@ -145,10 +143,7 @@ namespace lib
|
||||
{
|
||||
public StreamingContext Context { get; set; }
|
||||
|
||||
static Random s_rnd = new Random();
|
||||
int m_rndVal = s_rnd.Next();
|
||||
|
||||
XmlFormatter2Cfg m_cfg = new XmlFormatter2Cfg();
|
||||
private XmlFormatter2Cfg _cfg = new();
|
||||
|
||||
#region Unimplimented
|
||||
public ISurrogateSelector SurrogateSelector
|
||||
@ -174,7 +169,7 @@ namespace lib
|
||||
{
|
||||
//Context = new StreamingContext( StreamingContextStates.All );
|
||||
|
||||
m_cfg = cfg;
|
||||
_cfg = cfg;
|
||||
|
||||
log.warn( $"XML serialization is NOT fast" );
|
||||
}
|
||||
@ -189,10 +184,7 @@ namespace lib
|
||||
}
|
||||
|
||||
|
||||
public T Deserialize<T>(Stream stream)
|
||||
{
|
||||
return (T)DeserializeKnownType(stream, typeof(T));
|
||||
}
|
||||
public T Deserialize<T>( Stream stream ) => (T)DeserializeKnownType( stream, typeof( T ) );
|
||||
|
||||
public object DeserializeKnownType( Stream stream, Type t )
|
||||
{
|
||||
@ -222,10 +214,10 @@ namespace lib
|
||||
|
||||
public void DeserializeInto<T>( Stream stream, T obj )
|
||||
{
|
||||
XmlTextReader reader = new XmlTextReader( stream );
|
||||
XmlTextReader reader = new( stream );
|
||||
reader.Read();
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
XmlDocument doc = new();
|
||||
|
||||
doc.Load( reader );
|
||||
|
||||
@ -266,10 +258,7 @@ namespace lib
|
||||
return Deserialize( elem, null, type, null );
|
||||
}
|
||||
|
||||
private bool IsEnumerable( Type type )
|
||||
{
|
||||
return type.IsAssignableTo( typeof(IEnumerable) );
|
||||
}
|
||||
static private bool IsEnumerable( Type type ) => type.IsAssignableTo( typeof( IEnumerable ) );
|
||||
|
||||
private object Deserialize( XmlElement elem, MemberInfo mi, Type type, object existing /*, object enclosing = null*/ )
|
||||
{
|
||||
@ -514,7 +503,7 @@ namespace lib
|
||||
|
||||
bool filterFields, filterProps, doImpls, doFields, doProps;
|
||||
HashSet<string> whitelistFields, whitelistProps;
|
||||
GetFilters(m_cfg.TypesDefault, mi, narrowType, out filterFields, out filterProps, out doImpls, out doFields, out doProps, out whitelistFields, out whitelistProps);
|
||||
GetFilters( _cfg.TypesDefault, mi, narrowType, out filterFields, out filterProps, out doImpls, out doFields, out doProps, out whitelistFields, out whitelistProps );
|
||||
|
||||
if( doFields || doImpls )
|
||||
{
|
||||
@ -551,10 +540,12 @@ namespace lib
|
||||
name = refl.TypeToIdentifier( name );
|
||||
|
||||
// @@@ TODO This doesnt yet handle propNames!
|
||||
if (FilterField(filterFields, doImpls, whitelistFields, childFi as MemberInfo, name)) continue;
|
||||
if( FilterField( filterFields, doImpls, whitelistFields, childFi as MemberInfo, name ) )
|
||||
continue;
|
||||
|
||||
string attValue = elem.GetAttribute( name );
|
||||
if( !string.IsNullOrWhiteSpace( propName ) && string.IsNullOrWhiteSpace( attValue ) ) attValue = elem.GetAttribute( propName );
|
||||
if( !string.IsNullOrWhiteSpace( propName ) && string.IsNullOrWhiteSpace( attValue ) )
|
||||
attValue = elem.GetAttribute( propName );
|
||||
|
||||
if( !string.IsNullOrWhiteSpace( attValue ) )
|
||||
{
|
||||
@ -567,7 +558,8 @@ namespace lib
|
||||
else
|
||||
{
|
||||
XmlElement childElem = getNamedChild( allChildren, name );
|
||||
if( childElem == null && !string.IsNullOrWhiteSpace( propName ) ) childElem = getNamedChild( allChildren, propName );
|
||||
if( childElem == null && !string.IsNullOrWhiteSpace( propName ) )
|
||||
childElem = getNamedChild( allChildren, propName );
|
||||
|
||||
if( childElem != null )
|
||||
{
|
||||
@ -598,7 +590,8 @@ namespace lib
|
||||
|
||||
name = refl.TypeToIdentifier( name );
|
||||
|
||||
if (FilterField(filterProps, doImpls, whitelistProps, childPi as PropertyInfo, name)) continue;
|
||||
if( FilterField( filterProps, doImpls, whitelistProps, childPi as PropertyInfo, name ) )
|
||||
continue;
|
||||
|
||||
XmlElement childElem = getNamedChild( allChildren, name );
|
||||
|
||||
@ -631,10 +624,12 @@ namespace lib
|
||||
{
|
||||
if( doImpls )
|
||||
{
|
||||
if( mi.GetCustomAttribute<ChildAttributes>( true ) == null ) return true;
|
||||
if( mi.GetCustomAttribute<ChildAttribute>( true ) == null )
|
||||
return true;
|
||||
}
|
||||
|
||||
if( filterFields && !whitelistFields.Contains( name ) ) return true;
|
||||
if( filterFields && !whitelistFields.Contains( name ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -838,7 +833,7 @@ namespace lib
|
||||
{
|
||||
TypeCode tc = Type.GetTypeCode( type );
|
||||
|
||||
if( m_cfg.datastructure == Datastructure.Graph && refInt > 0 && m_alreadySerialized.ContainsKey( refInt ) )
|
||||
if( _cfg.datastructure == Datastructure.Graph && refInt > 0 && m_alreadySerialized.ContainsKey( refInt ) )
|
||||
{
|
||||
//lib.log.info( "Reusing object for {0}", refInt );
|
||||
return m_alreadySerialized[refInt];
|
||||
@ -858,7 +853,7 @@ namespace lib
|
||||
while( tryType != typeof( object ) && obj == null )
|
||||
{
|
||||
//m_cfg.TypeProxy.TryGetValue( )
|
||||
if( m_cfg.TypeProxy.TryGetValue( tryType, out var newProxy ) )
|
||||
if( _cfg.TypeProxy.TryGetValue( tryType, out var newProxy ) )
|
||||
{
|
||||
proxy = newProxy;
|
||||
break;
|
||||
@ -890,7 +885,8 @@ namespace lib
|
||||
// @@@ GROSS Fix the types so theyre known good.
|
||||
var isSubclass = type.IsSubclassOf( existingObjType ) || existingObjType.IsSubclassOf( type );
|
||||
|
||||
if( isSubclass ) return existingObj;
|
||||
if( isSubclass )
|
||||
return existingObj;
|
||||
|
||||
// old
|
||||
//if( type == existingObjType ) return existingObj;
|
||||
@ -926,7 +922,7 @@ namespace lib
|
||||
return obj;
|
||||
}
|
||||
|
||||
if( m_cfg.datastructure == Datastructure.Graph && refInt > 0 )
|
||||
if( _cfg.datastructure == Datastructure.Graph && refInt > 0 )
|
||||
{
|
||||
m_alreadySerialized[refInt] = obj;
|
||||
}
|
||||
@ -946,7 +942,7 @@ namespace lib
|
||||
{
|
||||
TypeCode elemTC = Type.GetTypeCode( elemType );
|
||||
|
||||
if( m_cfg.datastructure == Datastructure.Graph && refInt > 0 && m_alreadySerialized.ContainsKey( refInt ) )
|
||||
if( _cfg.datastructure == Datastructure.Graph && refInt > 0 && m_alreadySerialized.ContainsKey( refInt ) )
|
||||
{
|
||||
return (Array)m_alreadySerialized[refInt];
|
||||
}
|
||||
@ -954,7 +950,7 @@ namespace lib
|
||||
{
|
||||
Array arr = Array.CreateInstance( elemType, length );
|
||||
|
||||
if( m_cfg.datastructure == Datastructure.Graph )
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
m_alreadySerialized[refInt] = arr;
|
||||
|
||||
@ -1022,11 +1018,13 @@ namespace lib
|
||||
|
||||
if( typeCode != TypeCode.Object )
|
||||
{
|
||||
if( m_cfg.POD == POD.Elements || forceType ) writer.WriteStartElement( name );
|
||||
if( _cfg.POD == POD.Elements || forceType )
|
||||
writer.WriteStartElement( name );
|
||||
|
||||
SerializeConcrete( writer, mi, root, name, forceType );
|
||||
|
||||
if( m_cfg.POD == POD.Elements || forceType ) writer.WriteEndElement();
|
||||
if( _cfg.POD == POD.Elements || forceType )
|
||||
writer.WriteEndElement();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1063,9 +1061,10 @@ namespace lib
|
||||
private void SerializeConcrete( XmlWriter writer, MemberInfo mi, object root, string name, bool forceType )
|
||||
{
|
||||
//TODO: Only write this out if debugging.
|
||||
if( forceType || m_cfg.POD == POD.Elements )
|
||||
if( forceType || _cfg.POD == POD.Elements )
|
||||
{
|
||||
if( forceType ) writer.WriteAttributeString( "_.t", getTypeName( root.GetType() ) );
|
||||
if( forceType )
|
||||
writer.WriteAttributeString( "_.t", getTypeName( root.GetType() ) );
|
||||
writer.WriteAttributeString( "v", root.ToString() );
|
||||
}
|
||||
else
|
||||
@ -1090,14 +1089,14 @@ namespace lib
|
||||
|
||||
long refInt = m_objectID.GetId( root, out first );
|
||||
|
||||
if( m_cfg.datastructure == Datastructure.Graph )
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
writer.WriteAttributeString( "ref", refInt.ToString() );
|
||||
}
|
||||
|
||||
if( first )
|
||||
{
|
||||
if( m_cfg.datastructure == Datastructure.Graph )
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
m_alreadySerialized[refInt] = root;
|
||||
}
|
||||
@ -1118,22 +1117,20 @@ namespace lib
|
||||
|
||||
if( depth == 1 )
|
||||
{
|
||||
writer.WriteAttributeString( "_.version.", $"{m_cfg.Version}" );
|
||||
writer.WriteAttributeString( "_.version.", $"{_cfg.Version}" );
|
||||
}
|
||||
|
||||
bool first;
|
||||
|
||||
long refInt = m_objectID.GetId(root, out first);
|
||||
long refInt = m_objectID.GetId( root, out var first );
|
||||
|
||||
// @@@@ FIX for proxies.
|
||||
if( m_cfg.datastructure == Datastructure.Graph )
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
writer.WriteAttributeString( "ref", refInt.ToString() );
|
||||
}
|
||||
|
||||
if( first )
|
||||
{
|
||||
if (m_cfg.datastructure == Datastructure.Graph)
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
m_alreadySerialized[refInt] = root;
|
||||
}
|
||||
@ -1145,7 +1142,7 @@ namespace lib
|
||||
|
||||
if( root is ISerializable ser )
|
||||
{
|
||||
if ((root is Delegate))
|
||||
if( root is Delegate )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1174,7 +1171,7 @@ namespace lib
|
||||
|
||||
while( tryType != typeof( object ) )
|
||||
{
|
||||
if (m_cfg.TypeProxy.TryGetValue(tryType, out var newProxy))
|
||||
if( _cfg.TypeProxy.TryGetValue( tryType, out var newProxy ) )
|
||||
{
|
||||
proxy = newProxy;
|
||||
break;
|
||||
@ -1201,7 +1198,7 @@ namespace lib
|
||||
{
|
||||
bool filterFields, filterProps, doImpls, doFields, doProps;
|
||||
HashSet<string> whitelistFields, whitelistProps;
|
||||
GetFilters(m_cfg.TypesDefault, mi, narrowType, out filterFields, out filterProps, out doImpls, out doFields, out doProps, out whitelistFields, out whitelistProps);
|
||||
GetFilters( _cfg.TypesDefault, mi, narrowType, out filterFields, out filterProps, out doImpls, out doFields, out doProps, out whitelistFields, out whitelistProps );
|
||||
|
||||
if( doFields || doImpls )
|
||||
{
|
||||
@ -1230,7 +1227,8 @@ namespace lib
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FilterField(filterFields, doImpls, whitelistFields, childFi as MemberInfo, name)) continue;
|
||||
if( FilterField( filterFields, doImpls, whitelistFields, childFi as MemberInfo, name ) )
|
||||
continue;
|
||||
|
||||
object[] objs = childFi.GetCustomAttributes( typeof( NonSerializedAttribute ), true );
|
||||
|
||||
@ -1243,7 +1241,7 @@ namespace lib
|
||||
|
||||
name = refl.TypeToIdentifier( name );
|
||||
|
||||
var finalName = (m_cfg.Naming == BackingFieldNaming.Short && !string.IsNullOrEmpty( propName )) ?
|
||||
var finalName = ( _cfg.Naming == BackingFieldNaming.Short && !string.IsNullOrEmpty( propName ) ) ?
|
||||
propName :
|
||||
name;
|
||||
|
||||
@ -1265,7 +1263,8 @@ namespace lib
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FilterField(filterProps, doImpls, whitelistProps, childPi as MemberInfo, name)) continue;
|
||||
if( FilterField( filterProps, doImpls, whitelistProps, childPi as MemberInfo, name ) )
|
||||
continue;
|
||||
|
||||
object[] objs = childPi.GetCustomAttributes( typeof( NonSerializedAttribute ), true );
|
||||
|
||||
@ -1313,14 +1312,14 @@ namespace lib
|
||||
|
||||
long refInt = m_objectID.GetId( root, out first );
|
||||
|
||||
if( m_cfg.datastructure == Datastructure.Graph )
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
writer.WriteAttributeString( "ref", refInt.ToString() );
|
||||
}
|
||||
|
||||
if( first )
|
||||
{
|
||||
if( m_cfg.datastructure == Datastructure.Graph )
|
||||
if( _cfg.datastructure == Datastructure.Graph )
|
||||
{
|
||||
m_alreadySerialized[refInt] = root;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user