private void SetDataType() { if (OriginalType.IsEnum) { DataType = DataType.Enum; EnumType = OriginalType; } else if (TypeInfo.IsNumber(OriginalType)) { DataType = DataType.Numeric; } else if (OriginalType.In(typeof(DateTime), typeof(DateTime?))) { DataType = DataType.DateTime; } else if (OriginalType.In(typeof(bool), typeof(bool?))) { DataType = DataType.Bool; } else if (OriginalType == typeof(byte[])) { DataType = DataType.File; } else { DataType = DataType.Text; } }
public virtual bool IsAssignment(ICbValue obj, bool isCast) { if (obj is ParamNameOnly) { return(false); } if (IsList) { ICbList cbList = GetListValue; if (isCast && cbList.IsArrayType && obj.IsList) { return(true); // ToArrya() を行う特殊なキャスト } if (isCast && obj.IsList) { ICbList ListObj = obj.GetListValue; if (ListObj.IsArrayType) { return(true); // List<>(array) を行う特殊なキャスト } } if (OriginalType.IsAssignableFrom(obj.OriginalType)) { return(true); } } return(CbSTUtils.IsAssignment(OriginalType, obj.OriginalType, isCast)); }
public void WrapsAndUnwrapsObject() { var originalObject = new OriginalType(); var wrappedObject = _mocks.ClassUnderTest.Wrap <WrapperForOriginalType, OriginalType>(originalObject); Assert.Equal(originalObject, _mocks.ClassUnderTest.Unwrap <OriginalType>(wrappedObject)); }
public Replay(Queue <string> originalTrackData, Queue <string> originalInfoData, OriginalType originalType, int originalLength, int frameRate, int pxPERmm, string folder, string name, string fishID) : base(folder, name, fishID, originalLength, frameRate, pxPERmm) { if (FileSaver != null) { _trackWriter = FileSaver.GetStreamWriter(".track"); _imageWriter = FileSaver.GetTiffWriter("_camImage.tif", true); _backgroundWriter = FileSaver.GetTiffWriter("_bgImage.tif", true); //Create 10x10 mm region image _camRegion = new Image8(Properties.Settings.Default.PixelsPermm * 10, Properties.Settings.Default.PixelsPermm * 10); } _laser = new SDLPS500Controller(Properties.Settings.Default.DAQ, Properties.Settings.Default.LaserAO); string xchannel = Properties.Settings.Default.DAQ + "/" + Properties.Settings.Default.ScannerX; string ychannel = Properties.Settings.Default.DAQ + "/" + Properties.Settings.Default.ScannerY; //Load scan lookup table from file try { TextReader reader = File.OpenText("main.calib"); var scanTable = BLIScanLookupTable.LoadFromFile(reader); _scanner = new RandomAccessScanner(scanTable, xchannel, ychannel, -10, 10); reader.Dispose(); } catch (IOException) { System.Diagnostics.Debug.WriteLine("Could not find calibration data. No targeting available"); } //This is a closed-loop experiment - try to stay fully up-to-date SuggestedBufferSeconds = 0; _originalType = originalType; _originalTrackData = originalTrackData; _originalInfoData = originalInfoData; _experimentPhase = ExperimentPhase.Replay; }
protected void UpdateOriginalGenericArguments(ref int nullableFlagsIndex) { if (_originalGenericArguments == null) { lock (this) { if (_originalGenericArguments == null) { var arguments = new List <CachedType>(); #if NET40 foreach (var type in OriginalType.GetGenericArguments()) #else foreach (var type in OriginalType.GenericTypeArguments) #endif { arguments.Add(GetCachedType(type, ref nullableFlagsIndex)); } if (arguments.Count == 0) { var elementType = OriginalType.GetElementType(); if (elementType != null) { _elementType = GetCachedType(elementType, ref nullableFlagsIndex); } } _originalGenericArguments = arguments.ToArray(); _isNullableType = OriginalType.Name == "Nullable`1"; _genericArguments = _isNullableType ? arguments[0]._originalGenericArguments : _originalGenericArguments; _type = _isNullableType ? ((IEnumerable)_originalGenericArguments).Cast <CachedType>().First().OriginalType : OriginalType; } } } }
/// <summary> /// 检测类型是否启用 /// </summary> /// <param name="extension"></param> /// <returns></returns> private bool TypeEnabled(string extension, out OriginalType type) { switch (extension) { case ".txt": type = OriginalType.Txt; return(cache.txtEnabled); case ".csv": type = OriginalType.Csv; return(cache.csvEnabled); /* * case ".json": * type = OriginalType.Json; * return cache.jsonEnabled; * case ".xml": * type = OriginalType.Xml; * return cache.xmlEnabled; */ case ".xlsx": type = OriginalType.Xlsx; return(cache.xlsxEnabled); } type = OriginalType.Txt; return(false); }
public static void WriteJson(this OriginalType value, JsonWriter writer, JsonSerializer serializer) { switch (value) { case OriginalType.Empty: serializer.Serialize(writer, ""); break; } }
public void WrapsObjectWithBridge() { var originalObject = new OriginalType(); var wrappedObject = _mocks.ClassUnderTest.Wrap <WrapperForOriginalTypeWithBridge, OriginalType>(originalObject); Assert.NotNull(wrappedObject.Bridge); }
public override IEnumerable <Member> GlmMembers() { if (OriginalType is SwizzleType) { yield break; // nothing for swizzling } if (Visibility != "public") { yield break; } if (this is ExplicitOperator) { yield break; } if (this is ImplicitOperator) { yield break; } if (this is Operator) { yield break; } if (Static) { var paras = Parameters.ParasRecovered().ToArray(); if (paras.Length == 0) { throw new NotSupportedException(); } var ptype = paras[0].Split(' ')[0]; if (ptype == OriginalType.NameThat) { yield return(new Function(ReturnType, Name + OriginalType.GenericSuffix) { Inline = true, Static = true, Parameters = Parameters, Comment = Comment, CodeString = $"{OriginalType.NameThat}.{Name}({Parameters.ArgNames().CommaSeparated()})" }); } yield break; // nothing for static props } var varname = OriginalType is VectorType ? "v" : OriginalType is QuaternionType ? "q" : "m"; yield return(new Function(ReturnType, Name + OriginalType.GenericSuffix) { Inline = true, Static = true, Comment = Comment, Parameters = OriginalType.TypedArgs(varname).Concat(Parameters), CodeString = $"{varname}.{Name}({Parameters.ArgNames().CommaSeparated()})" }); }
internal object GenerateInstance(Type type) { if (type != OriginalType && !OriginalType.IsAssignableFrom(type)) { throw new Exception(string.Format("Provided type does not match or inherit from '{0}'", OriginalType.FullName)); } var options = new ProxyGenerationOptions(new CryptInjectHook()); options.AddMixinInstance(Activator.CreateInstance(MixinType)); return(Generator.CreateClassProxy(OriginalType, options, new EncryptedDataStorageInterceptor())); }
EventDescriptorCollection ITypeDescriptionProvider.GetEvents() { EventInfo[] ei = OriginalType.GetEvents(); EventDescriptor[] ed = new EventDescriptor[ei.Length]; for (int i = 0; i < ei.Length; i++) { ed[i] = new CustomEventDescriptor(ei[i]); } return(new EventDescriptorCollection(ed)); }
private void DeterminePropertyInfo() { // for example for string PropertyType.GetInterface("IEnumerable`1") // is not null, so we must check if type has sub type IsCollection = OriginalType.GetInterface("IEnumerable`1") != null && OriginalType.GetGenericArguments().Any(); if (IsCollection) { var subType = OriginalType.GetGenericArguments().Single(); OriginalType = subType; } IsSystemType = OriginalType.Namespace.StartsWith("System"); }
private void InitializeNullableFlagsAndOriginalNullability(ref int nullableFlagsIndex, IEnumerable <dynamic> customAttributeProviders) { try { if (_nullableFlags == null) { var nullableAttribute = ContextAttributes.FirstOrDefault(a => a.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute"); if (nullableAttribute != null) { _nullableFlags = GetFlagsFromNullableAttribute(nullableAttribute); } else if (customAttributeProviders != null) { _nullableFlags = GetFlagsFromCustomAttributeProviders(customAttributeProviders); } else { _nullableFlags = new byte[] { 0 }; } } } catch { _nullableFlags = new byte[] { 0 }; #if DEBUG throw; #endif } if (OriginalType.GetTypeInfo().IsValueType) { OriginalNullability = Nullability.NotNullable; } else { var nullableFlag = _nullableFlags.Length > nullableFlagsIndex ? _nullableFlags[nullableFlagsIndex] : _nullableFlags.Last(); nullableFlagsIndex++; OriginalNullability = nullableFlag == 0 ? Nullability.Unknown : nullableFlag == 1 ? Nullability.NotNullable : nullableFlag == 2 ? Nullability.Nullable : Nullability.Unknown; } }
/// <summary> /// Creates the data set section of the SPARQL query. /// </summary> /// TODO: Determine whether the changes to the Data Set clause break the case for named graphs. /// <param name="sb">A <see cref="StringBuilder"/> onto which the clause should be appended.</param> private void CreateDataSetClause(StringBuilder sb) { #if false // As was // related Issue: #12 http://code.google.com/p/linqtordf/issues/detail?id=12 string graph = OriginalType.GetOntology().GraphName; if (!graph.Empty()) { sb.AppendFormat("FROM NAMED <{0}>\n", graph); } return; // no named graphs just yet () #else string defaultGraph = DataContext.DefaultGraph; if (!string.IsNullOrEmpty(defaultGraph)) { sb.AppendFormat("FROM <{0}>\n", defaultGraph); } return; #endif }
void FromFloatingPoint(double floatValue, OriginalType type) { _hashCode = (long)(floatValue * FloatingPrecision); _data[0] = (byte)type; // If no precision was lost, no need to keep the original value otherwise store it // If possible, storing it as an int mai handle the precision better than the double (1.7 for example if (_hashCode % 10 != 0) { var original = BitConverter.GetBytes(floatValue); var data = new byte[1 + original.Length]; data[0] = _data[0]; Buffer.BlockCopy(original, 0, data, 1, original.Length); _data = data; } }
protected MemberInfo GetMember(int memberType, string memberName) { const BindingFlags allInstaceMembers = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; MemberInfo mi; switch (memberType) { case 1: mi = Type.GetField(memberName, allInstaceMembers); break; case 2: mi = Type.GetProperty(memberName, allInstaceMembers) ?? OriginalType.GetProperty(memberName, allInstaceMembers); break; default: throw new InvalidOperationException(); } return(mi); }
private void InitializeNullableFlagsAndOriginalNullability(ref int nullableFlagsIndex, IEnumerable <dynamic> customAttributeProviders) { try { if (_nullableFlags == null) { var nullableAttribute = ContextAttributes.FirstOrDefault(a => a.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute"); if (nullableAttribute != null) { _nullableFlags = GetFlagsFromNullableAttribute(nullableAttribute); } else if (customAttributeProviders != null) { _nullableFlags = GetFlagsFromCustomAttributeProviders(customAttributeProviders); } else { _nullableFlags = new byte[] { 0 }; } } } catch { _nullableFlags = new byte[] { 0 }; #if DEBUG throw; #endif } if (OriginalType.GetTypeInfo() is var typeInfo && typeInfo.IsValueType) { if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() != typeof(Nullable <>)) { nullableFlagsIndex++; } OriginalNullability = Nullability.NotNullable; }
void FromLong(long longValue, OriginalType type) { _hashCode = longValue; _data[0] = (byte)type; }
// public override TypeReference[] GenericArguments // { // get // { // return OriginalType.GenericArguments; // } // } // // public override GenericParameter[] GenericParameters // { // get // { // return OriginalType.GenericParameters; // } // } public override TypeReference GetElementType() { return(OriginalType.GetElementType()); }
EventDescriptor ITypeDescriptionProvider.GetEvent(string name) { return(new CustomEventDescriptor(OriginalType.GetEvent(name))); }
/// <summary> /// Creates the where clause of the SPARQL query - the part that indicates what the properties of selected objects should be. /// </summary> /// <param name="sb">A <see cref="StringBuilder"/> into which the SPARQL should be inserted.</param> private void CreateWhereClause(StringBuilder sb) { // if using an identity projection then every available property of the type must be returned bool isIdentityProjection = OriginalType == typeof(T); // if there is no where clause then we want every instance back (and we won't be filtering) // the logic around this is a little tricky (or debatable) - // Given that you could have instances that are partially complete in the triple store (i.e. not all triples are present) // you need to be able to ensure that a query that does not explicitly include the missing properties does not // exclude any instances where those properties are missing. // I've reasoned that if you perform an identity projection, then you're saying "get me whatever you can", whereas if // you specifically request a certain property (via a projection) then you really must want a value for that, and thus // instances must be excluded where there is no value _known_ - Hence the '|| IsIdentityProjection'. bool getAnythingThatYouCan = !(Expressions.ContainsKey("Where")) || isIdentityProjection /* */; // using "$" distinguishes this varName from anything that could be introduced from the properties of the type // therefore the varName is 'safe' in the sense that there can never be a name clash. string varName = "$" + GetInstanceName(); sb.Append("WHERE {\n"); // if parameters have been defined somewhere. If using an identity projection then we will not be getting anything from projectionParameters // if we have no WHERE expression, then we also won't be getting anything from queryGraphParameters var parameters = new List <MemberInfo>(QueryGraphParameters.Union(ProjectionParameters)); if (parameters.Count == 0) { // is it an identity projection? If so, place all persistent properties into parameters if (isIdentityProjection) { foreach (PropertyInfo info in OwlClassSupertype.GetAllPersistentProperties(OriginalType)) { parameters.Add(info); } } } // if (parameters.Count > 0) // { sb.AppendFormat("{0} a {1}:{2} .\n", varName, OriginalType.GetOntology().Prefix, OriginalType.GetOwlResource().RelativeUriReference); // } // else // { // // I don't think there is any way to get into to this point unless the object is persistent, but has no // throw new ApplicationException( // "No persistent properties defined on the entity. Unable to generate a query."); // } // // temp var to get the object variables list IEnumerable <MemberInfo> args; // a temp string to get the tripleFormat that will be used to generate query triples. string tripleFormat = "OPTIONAL{{{0} {1}:{2} ?{3} .}}\n"; if (!getAnythingThatYouCan) { tripleFormat = "{0} {1}:{2} ?{3} .\n"; } if (isIdentityProjection) { args = OwlClassSupertype.GetAllPersistentProperties(OriginalType); } else { args = parameters; } foreach (MemberInfo arg in args) { // The ontology and prefix assigned to a class property need not match those assigned to the class itself. // e.g. The class could have a property which maps to foaf:name, or dc:title. OwlResourceAttribute ora = arg.GetOwlResource(); sb.AppendFormat(tripleFormat, varName, AttributeExtensions.GetOntologyPrefix(ora.OntologyName), //WAS: originalType.GetOntology().Prefix, ora.RelativeUriReference, arg.Name); } if (!string.IsNullOrEmpty(PropertyReferenceTriple)) { sb.AppendLine(PropertyReferenceTriple); } if (!string.IsNullOrEmpty(FilterClause)) { sb.AppendFormat("FILTER( {0} )\n", FilterClause); } sb.Append("}\n"); }
public void WrapsNullAsNull() { OriginalType obj = null; Assert.Null(_mocks.ClassUnderTest.Wrap <WrapperForOriginalType, OriginalType>(obj)); }
private void InitializeNullableFlagsAndOriginalNullability(ref int nullableFlagsIndex, IEnumerable <dynamic>?customAttributeProviders) { var typeInfo = OriginalType.GetTypeInfo(); try { if (_nullableFlags == null) { var nullableAttribute = ContextAttributes.FirstOrDefault(a => a.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute"); if (nullableAttribute is not null) { _nullableFlags = GetFlagsFromNullableAttribute(nullableAttribute); } else if (typeInfo.IsGenericParameter) { nullableAttribute = typeInfo.GetCustomAttributes().FirstOrDefault(a => a.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute"); if (nullableAttribute is not null) { _nullableFlags = GetFlagsFromNullableAttribute(nullableAttribute); } else { // Default nullability (NullableContextAttribute) from the context _nullableFlags = GetFlagsFromCustomAttributeProviders(typeInfo.DeclaringType.IsNested ? new dynamic[] { typeInfo.DeclaringType, typeInfo.DeclaringType.DeclaringType } : new dynamic[] { typeInfo.DeclaringType }); } } else if (customAttributeProviders is not null) { // Default nullability (NullableContextAttribute) from the context _nullableFlags = GetFlagsFromCustomAttributeProviders(customAttributeProviders); } else { _nullableFlags = new byte[] { 0 }; // Unknown } } } catch { _nullableFlags = new byte[] { 0 }; #if DEBUG throw; #endif } if (typeInfo.IsValueType) { if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() != typeof(Nullable <>)) { nullableFlagsIndex++; } OriginalNullability = Nullability.NotNullable; } else { var nullableFlag = _nullableFlags.Length > nullableFlagsIndex ? _nullableFlags[nullableFlagsIndex] : _nullableFlags.Last(); nullableFlagsIndex++; OriginalNullability = nullableFlag == 0 ? Nullability.Unknown : nullableFlag == 1 ? Nullability.NotNullable : nullableFlag == 2 ? Nullability.Nullable : Nullability.Unknown; } }
public override string ToString() { return(OriginalType.FullName(".") + " -> " + TargetType.FullName(".") + (string.IsNullOrEmpty(TargetID) ? "" : "(" + TargetID + ")")); }